<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>东财涨停股池</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">			
			nav a{	
			padding: 1em 1em;
			letter-spacing: -100px;			
			}			  
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}					  
			#towrite {margin-top:-10px}	
			table{
			width:460px; 
			border-collapse:collapse; 
			text-align:center;
			}
			td,th{border:1px solid #696969}					
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>
			var g = 0;  //不要1板改为0  ,要点“清除缓存”
			var day = new Date();
			var tt = "";			
			window.onload = function() {			
			mymonth = day.getMonth()+1;
			myday = day.getDate();
			if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
			if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
			tt = day.getFullYear() + "-" + mymonth + "-" + myday;
					
			getSource();
			changeStyle();
			}
								
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {
				var obj	 = document.getElementById("towrite");	
				obj.style.left= "0px"; 				
				obj.style.width= "500px";
				//obj.style.height= "620px";						
				obj.style.fontSize="12px";
			}
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function UnUnicode(str) {
					return unescape(str.replace(/\\/g, "%"));
				}			
			
			function cDayFunc(dp) 
			{ 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			function BookingRmk(date)
			{         
				//var PriceDate = date;    
				//alert(PriceDate);
				tt = date;							
				getSource();
			}
			
			var trid = "";
			function changeCss(obj,hid,id){						
				var tlist = document.getElementById(id).getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = "#252528"; 					
				}
				trid = hid;
				var tr = document.getElementById(hid);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hover(){  //鼠标经过
				var rows = document.getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){						
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头
							if(this.id != trid){  //过滤选中行
								this.style.background="#252528";
							}else{
								this.style.background="#483D8B";
							}
						}						
					}					
				}
			}			
			
			
			function keepTwoDecimal(num) {  
				   var result = parseFloat(num);  
				   if (isNaN(result)) {  
					   //alert('传递参数错误，请检查！');  
					   return false;  
				   }  
				   result = Math.round(num * 100) / 100;  
				   return result;  
			};
		
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000)
			   {
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }
				else if(Math.abs(num) > 10000)
			   {
			    result = num/10000;
				result = result.toFixed(2) + "万";
			   }				   
               return result;  
			};	
			
			function updated() {  //判断最后交易日
				day = new Date(tt);	
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() - 24*60*60*1000);							
					}
					tt = day.Format("yyyy-MM-dd");
					url = "http://push2ex.eastmoney.com/getTopicZTPool?cb=callbackdata1207668&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=1000&sort=lbc%3Adesc&date=" + tt.replace(/-/g,""); 					
					var xhr = new XMLHttpRequest();	
					xhr.open("GET", url, false);
					xhr.send(null)																										
					var data1 = xhr.responseText;					
					if(data1.indexOf('"data":null') == -1)
					{
						break;
					}
				}				
			}	
			
			var fx = "";
			var fs = "";
			var x = "";
			var gl = "";  //高亮
			function getSource() {
				updated();			
				div = document.getElementById('towrite');
				div.innerHTML = '<font size="2">东财涨停股池&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 120px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
				
				//div.innerHTML = div.innerHTML + "<p>排序（" + p1 + p2 + p3 + "）</p>";					
				document.getElementById("PriceDate").value = tt;				
				
				url = "http://push2ex.eastmoney.com/getTopicZTPool?cb=callbackdata1207668&ut=7eea3edcaed734bea9cbfc24409ed989&dpt=wz.ztzt&Pageindex=0&pagesize=1000&sort=lbc%3Adesc&date=" + tt.replace(/-/g,""); 					
				
				if (window.XMLHttpRequest) {
						xmlHttp = new XMLHttpRequest();				
					} else {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");				
					}				
					xmlHttp.onreadystatechange = writeSource;
					xmlHttp.open("GET", url, true);
					xmlHttp.send(null);			
			}
			
			function writeSource() { 
				if (xmlHttp.readyState == 4 ) {         					
					var data = xmlHttp.responseText					
					//document.write(data);	
									
					if(data.indexOf('"data":null') == -1){
						data = data.replace(/ /g,"").match(/\"pool\":(\S*)\}\}\);/)[1];
						//document.write(data);
						data = data.replace(/(\{\").*?(?=\})/g,function(word){ 				
							str = word.match(/\{(\S*)/)[1];	
							var lb = str.split(',')[9];					
							lb = lb.match(/"lbc":(\S*)/)[1];
							if(g == 1){
								return "{" + str.split(',')[0] + "," + str.split(',')[2] + "," + str.split(',')[4] + "," + str.split(',')[12] + "," + str.split(',')[9] + ","	+ str.split(',')[14];
							}else if(g == 0 && parseInt(lb) > 1){
								return "{" + str.split(',')[0] + "," + str.split(',')[2] + "," + str.split(',')[4] + "," + str.split(',')[12] + "," + str.split(',')[9] + ","	+ str.split(',')[14];	
							}else{
								return "";
							}							
						});
						data = data.replace(/}},{/g,"},{").replace(/}}]/g,"}]").replace(/}},/g,"");
						//document.write(data);
						
						//涨幅				
						data = data.replace(/(\"zdp\":).*?(?=,)/g, function(word){ 				
							str = word.match(/\"zdp\":(\S*)/)[1]; 					
							return '\"zdp\":"' + keepTwoDecimal(str) + '"';
						});
						
						//封单额				
						data = data.replace(/(\"fund\":).*?(?=,)/g, function(word){ 						
						str = word.match(/\"fund\":(\S*)/)[1]; 					
								if(keepTwoDecimal(Math.abs(str/100000000)) >= 1){
									return '\"fund\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
								}else{
									return '\"fund\":\"' + Math.round(str/10000) + '万\"';
								}					
						});
								
						var json = JSON.parse(data);				
						//创建table					
						var table=document.createElement("table");										
						var thead=document.createElement("thead");
						table.appendChild(thead);					
						var tr=document.createElement("tr");
						thead.appendChild(tr);					
						
						var m = 0;
						var v = 0;
						var b = 0;
						var gl = "连板";  //高亮
						for(var key in json[0]){  //表头
							key = key.replace('lbc','连板').replace('fund','封单额').replace('zdp','涨幅%').replace('hybk','行业板块').replace('c','代码').replace('n','名称');
							
							var th=document.createElement("th");						
							th.innerHTML=key;						
							tr.appendChild(th);
							if(gl == key.replace("%","")){
								v = m;
								th.style.color = "#FF6633";	
							}
							if(key == "行业板块"){
								b = m;
								th.style.color = "#FFA500";	
							}
							m++;
						}
											
						var tbody=document.createElement("tbody");					
						table.appendChild(tbody);
						
						//遍历json
						for(var i = 0; i < json.length; i++){					
							var tr=document.createElement("tr");						
							var p = 1;
							var dm = "";
							var mc = "";
							for(var key in json[i]){ //行元素遍历						
								var td=document.createElement("td");							
								var rc = json[i][key];
								if(p == 1){  //代码列
									dm = rc;
									tr.id = dm;
								}else if(p == 2){  //名称列
									mc = rc;								
								}	
								td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeCss(this,\"" + dm + "\",\"gg\")'>" + rc + "</a>";
							
							
								if(p == v + 1){							
									td.getElementsByTagName("a")[0].style.color = "#FF6633";
								}
								if(p == b + 1){							
									td.getElementsByTagName("a")[0].style.color = "#FFA500";
								}							
								tr.appendChild(td);
								p++;
							}						
							tbody.appendChild(tr);
						}					
						var div = document.getElementById("towrite");									
						div.appendChild(table);
						table.id = "gg";					
						makeSortable(table)
						hover();
					}										
				}
			}	
			
			function makeSortable(table) {			
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
													
							showCol(table,n);		//高亮
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("连板") != -1 || headtxt.indexOf("涨停原因") != -1){
									val1 = val1;
									val2 = val2;
								}else{											
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
							});
							if(flag){
								rows.reverse();
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}

							flag=!flag;
						}
					}(i));
				}
			}
			
			function showCol(table,iCol){			
				var oTable = table;
				var id = oTable.id;
				for (i=0;i < oTable.rows.length; i++){										
					for (j=0;j < oTable.rows[0].cells.length; j++){						
						oTable.rows[i].cells[j].style.color = "#d2d2d3";						
						oTable.rows[i].cells[5].style.color = "#FFA500";										
					}
					oTable.rows[i].cells[iCol].style.color = "#FF6633";					
				}
				
				var otagsA = oTable.getElementsByTagName("a");  //a变色
				for (i = 0; i < otagsA.length; i++) {
					otagsA[i].style.color = "#d2d2d3";					
					if(otagsA[i].id == 6){
						otagsA[i].style.color = "#FFA500";								
					}
					if(otagsA[i].id == iCol + 1){
						otagsA[i].style.color = "#FF6633";
					}
				}				
			}			
		</script>
	</head>

	<body>
		<div id="towrite" class="fixedBox">			
		</div>	
	</body>
</html>